﻿using System;
using System.IO;
using System.Web;
using System.Web.SessionState;

namespace CMS.Web.Manage.Ashx {
	/// <summary>
	/// 生成字符或图片格式的随机效验码
	/// </summary>
	public class Captcha : IHttpHandler, IRequiresSessionState {

		public void ProcessRequest(HttpContext context) {
			string captcha = Common.Captcha.CreateCaptcha(4);
			MemoryStream image = Common.Captcha.CreateImage(captcha);
			
			context.Session["Captcha"] = captcha;
			
			context.Response.Clear();
			context.Response.ContentType = "image/jpeg";
			context.Response.BinaryWrite(image.ToArray());
		}

		public bool IsReusable {
			get {
				return false;
			}
		}
	}
}